<?php

namespace app\common\model;

use think\Model;

/**
 *新闻模块model
 */
class News extends Model
{

    /**
     * 后台 新闻分页列表
     */
    public static function page_lists($map, $cate_id = '')
    {
        return self::where($map)->where(['is_del' => 0])->order('is_top desc,is_rec desc,sort zasc,id desc')->paginate(15, false, ['query' => ['cate_id' => $cate_id]]);

    }

    /**
     * 前台新闻列表展示
     */
    public static function news_lists($cate_id, $simple = false)
    {
        $cate_paginate = (new \app\common\model\NewsCate())::where(['id' => $cate_id])->value('paginate');
        $cate_paginate = 6;

        $field = 'id,news_title,news_headpic,news_brief,news_content,create_time';
        return self::where(['belong_cate_id' => $cate_id, 'is_pass' => 1, 'is_del' => 0])->order('is_top desc,id desc,sort asc')->field($field)->paginate($cate_paginate, $simple);
    }

    /**
     *上一篇 下一篇
     */
    public static function prev_news($id, $belong_cate_id)
    {
        return self::where('id', '<', $id)->where(['belong_cate_id' => $belong_cate_id, 'is_pass' => 1, 'is_del' => 0])->field('id,news_title')->find();
    }

    public static function next_news($id, $belong_cate_id)
    {
        return self::where('id', '>', $id)->where(['belong_cate_id' => $belong_cate_id, 'is_pass' => 1, 'is_del' => 0])->field('id,news_title')->find();
    }

    /**
     * 前台根据条件取栏目新闻
     */
    public static function get_cate_news($where, $limit = '', $order = '', $field = '')
    {
        return self::where($where)->where(['is_pass' => 1, 'is_del' => 0])->limit($limit)->field($field)->order($order)->select();
    }
}
